<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增学生')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-student-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">学生姓名：</label>
                <div class="col-sm-8">
                    <input name="stuName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">学生年龄：</label>
                <div class="col-sm-8">
                    <input name="stuAge" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">出生日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="birth" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">联系电话：</label>
                <div class="col-sm-8">
                    <input name="phone" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">家庭住址：</label>
                <div class="col-sm-8">
                    <input name="address" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所属班级：</label>
                <div class="col-sm-8">
                    <input name="classId" class="form-control" type="hidden">
                </div>
                <div class="col-xs-4">
                    <select id="classId" class="form-control select2-multiple">
                        <option th:each="class:${class}" th:value="${class.id}" th:text="${class.className}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所属宿舍：</label>
                <div class="col-sm-8">
                    <input name="roomId" class="form-control" type="hidden">
                </div>
                <div class="col-xs-4">
                    <select id="roomId" class="form-control select2-multiple">
                        <option th:each="room:${room}" th:value="${room.id}" th:text="${room.roomName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">报名的课程：</label>
                <div class="col-sm-8">
                    <input name="courseId" class="form-control" type="hidden">
                </div>
                <div class="col-xs-4">
                    <select id="courseId" class="form-control select2-multiple" multiple>
                        <option th:each="course:${course}" th:value="${course.id}" th:text="${course.courseName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">账号：</label>
                <div class="col-sm-8">
                    <input name="pAccount" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">密码：</label>
                <div class="col-sm-8">
                    <input name="pPassword" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/student"
        $("#form-student-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            // 获取所选下拉框的值
            var selectedClassId = $('#classId').val();
            // 将所选值赋给隐藏的输入文本框
            $('input[name="classId"]').val(selectedClassId);
            // 获取所选下拉框的值
            var selectedRoomId = $('#roomId').val();
            // 将所选值赋给隐藏的输入文本框
            $('input[name="roomId"]').val(selectedRoomId);
            // 获取所选下拉框的值
            var selectedCourseId = $('#courseId').val();
            // 将所选值赋给隐藏的输入文本框
            $('input[name="courseId"]').val(selectedCourseId);
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-student-add').serialize());
            }
        }

        $("input[name='birth']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>
